from urllib.parse import quote_plus

import pandas as pd
import requests
from sqlalchemy import create_engine



def mysql_config():
    user = 'live_data'
    password = quote_plus('CJMg2tsHg7sj6bo0UTKq0a4T!fPDpJ')
    # passwd ='merchantsasd123!@%&'
    host = 'rm-bp17r99475xuauk63yo.mysql.rds.aliyuncs.com'
    # port1 ='3306'
    dbname2 = 'live_data'
    engine2 = create_engine(f"mysql+pymysql://{user}:{password}@{host}:3306/{dbname2}?charset=utf8mb4")
    return engine2

data_info = pd.read_sql("select * from live_data.xhs_user_info where win='A'",mysql_config())
data_list = [data_info.loc[i].to_dict() for i in data_info.index.values]
for i in data_list:
    # print(i)
    data = {
        "env":0,
        "biztype":1,
        "xhs_account":i["xhs_account"]
    }
    ##a480d42fedad439ca11bf6e3259b6503
    url = "http://127.0.0.1:5006/xhs/unbind/DeleteUser"

    data2 = requests.post(url,json=data)
    print(data2)


# data = pd.read_sql("select distinct user_id from live_data.xhs_user_no_login",mysql_config())
# aa = []
# for i in data.iterrows():
#
#     data1 = pd.read_sql("select xhs_account from live_data.xhs_user_info where spider_user_id='{}'".format(i[1]["user_id"]),mysql_config())
#     for j in data1.iterrows():
#         aa.append(j[1]["xhs_account"])
#         print(j[1]["xhs_account"])
#     # print(i[1]["user_id"])
#     #     data2 = requests.post(url,json=id_re(j[1]['xhs_account']))
#     #     print(data2.text)
#
# print(aa)